/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.himaci.gtbattle.view;

import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector3;
import com.himaci.framework.BaseScreen;
import com.himaci.gtbattle.GTBattle;
import com.himaci.gtbattle.controller.GameplayController;
import com.himaci.gtbattle.model.AI;
import com.himaci.gtbattle.resource.Assets;

/**
 *
 * @author XNPSDN
 */
public class MainMenuScreen extends BaseScreen {

    Vector3 touchPoint;
    Rectangle playAILevel1;
    Rectangle playAILevel2;
    Rectangle playAILevel3;
    Rectangle statistic;
    Rectangle exit;

    public MainMenuScreen(Game game) {
	super(game);
	touchPoint = new Vector3();

	playAILevel1 = new Rectangle(72, 108, 100, 100);
	playAILevel2 = new Rectangle(187, 108, 100, 100);
	playAILevel3 = new Rectangle(302, 108, 100, 100);
	statistic = new Rectangle(285, 10, 200, 50);
	exit = new Rectangle(480 - 50, 320 - 50, 50, 50);
    }

    @Override
    public void update(float deltaTime) {
	if (Gdx.input.justTouched()) {
	    camera.unproject(touchPoint.set(Gdx.input.getX(), Gdx.input.getY(), 0));
	    if (playAILevel1.contains(touchPoint.x, touchPoint.y)) {
		GameplayController.getInstance().aiLevel = AI.LEVEL_EASY;
		GameplayController.getInstance().reset();
		((GameplayScreen)GTBattle.gameplayScreen).reset();
		game.setScreen(GTBattle.gameplayScreen);
		return;
	    }
	    if (playAILevel2.contains(touchPoint.x, touchPoint.y)) {
		GameplayController.getInstance().aiLevel = AI.LEVEL_MEDIUM;
		GameplayController.getInstance().reset();
		((GameplayScreen)GTBattle.gameplayScreen).reset();
		game.setScreen(GTBattle.gameplayScreen);
		return;
	    }
	    if (playAILevel3.contains(touchPoint.x, touchPoint.y)) {
		GameplayController.getInstance().aiLevel = AI.LEVEL_HARD;
		GameplayController.getInstance().reset();
		((GameplayScreen)GTBattle.gameplayScreen).reset();
		game.setScreen(GTBattle.gameplayScreen);
		return;
	    }
	    if (statistic.contains(touchPoint.x, touchPoint.y)) {
		game.setScreen(GTBattle.aboutScreen);
		return;
	    }
	    if (exit.contains(touchPoint.x, touchPoint.y)) {
		Gdx.app.exit();
	    }
	}
    }

    @Override
    public void present(float deltaTime) {
	Gdx.gl.glClearColor(Color.WHITE.r, Color.WHITE.g, Color.WHITE.b, 1);
	Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

	camera.update();
	batcher.setProjectionMatrix(camera.combined);

	batcher.disableBlending();
	batcher.begin();
	batcher.draw(Assets.getInstance().mainMenu, 0, 0);
	batcher.end();
    }

    @Override
    public void resize(int width, int height) {
    }

    @Override
    public void show() {
    }

    @Override
    public void hide() {
    }

    @Override
    public void pause() {
    }

    @Override
    public void resume() {
    }

    @Override
    public void releaseResource() {
    }
}
